# mysql helper functions
#
# Copyright (C) 2012-2012 Christian T. Steigies <steigies@physik.uni-kiel.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""mysql helper functions
"""

__author__ = "Christian T. Steigies <steigies@physik.uni-kiel.de>"
__license__ = "GPL License"

from datetime import datetime

## --------------------------------------------------------------------------
"""
executemany uses many INSERTS with only one VALUE, instead of one INSERT with many VALUES
see https://answers.launchpad.net/myconnpy/+question/120598
until this is fixed, use execute instead of executemany and prepare the VALUES with this helper function
"""

def values(list):
    #print list
    ret = "("
    delimiter = ""
    for i in list:
        #print i, type(i)
        if i is None:
            val ="NULL"
        elif type(i) is type("string"):
            val = "\"" + str(i) + "\""
        elif type(i) is type(u"unicode"):
            val = "\"" + str(i) + "\""
        elif type(i) is type(datetime(2000,1,1,0,0,0)):
            val = "\"" + str(i) + "\""
        else:
            val = str(i)
        ret = ret + delimiter + val
        if not delimiter:
            delimiter = ", "
    ret = ret + ")"
    return ret


## --------------------------------------------------------------------------
